/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.domains.prey;

import java.io.PrintStream;
import uk.ac.bath.base.Point;
import uk.ac.bath.util.MyRandom;

/**
 *
 * @author pjl
 */
public class MyPoint implements Point {

    public static float abs(MyPoint diff) {
         float val=(float) Math.sqrt(diff.x*diff.x+diff.y*diff.y);
         return val;
    }

    /**
     * returns vector vector from the ref to the target
     *
     * @param ref
     * @param target
     * @param res
     */
    static void diff(MyPoint ref, MyPoint target,MyPoint res) {
        res.x=target.x - ref.x ;
        res.y= target.y -ref.y;
    }

    public static void project(MyPoint pos, MyPoint dir, float vel, MyPoint res) {
        if (res == null) {
            res = new MyPoint();
        }
        res.x = pos.x + dir.x * vel;
        res.y = pos.y + dir.y * vel;
     
    }
    public float x;
    public float y;

    public MyPoint(float x, float y) {
        this.x = x;
        this.y = y;
    }

    public MyPoint(Point p) {
        this.x = p.getX();
        this.y = p.getY();
    }

    public MyPoint() {
    }

    public void moveBy(MyPoint d) {
        x += d.x;
        y += d.y;
    }

    public void multBy(float f) {
        x *= f;
        y *= f;
    }

    public double getAngle() {
        return Math.atan2(y, x);
    }

    void moveTo(MyPoint proj) {
        x = proj.x;
        y = proj.y;
    }

    public void save(PrintStream out) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void set(Point p) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public float getX() {
        return  x;
    }

    public float getY() {
        return  y;
    }

    public float getZ() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object clone() {
        return new MyPoint(x, y);
    }

    void randomDirection() {
        double xx;
        double yy;
        double zz;

        do {
            xx = 0.5 - MyRandom.nextDouble();
            yy = 0.5 - MyRandom.nextDouble();

            zz = Math.sqrt(xx * xx + yy * yy);
        } while (zz <= 0.0f);
        x = (float) (xx / zz);
        y = (float) (yy / zz);

    }

    public int getIX() {
        return (int)x;
    }

    public int getIY() {
        return (int)y;
        
    }

    public int getIZ() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   

}
